package cn.pconline.officialclub.entity;

import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

/**
 * 官方车友会焦点图
 *
 * @author <a href="mailto:chensy0203@163.com">chensy</a>
 */
@Entity(tableName = "oac_club_focus_img")
public class OClubFocusImg extends EntityKit {

    public static final String DEF_IMG = "http://img0.pcauto.com.cn/pcauto/1501/23/5840763_280x140.jpg";
    public final static int DB_MAX_LENGTH = 255;
    public static final int EMPTY_SEQ = 9; //空焦点图的seq
    /**
     * 焦点图ID
     */
    @Id
    @Column(name = "focus_img_id")
    private long focusImgId;
    /**
     * 车友会ID
     */
    @Column(name = "o_club_id")
    private long oClubId;
    /**
     * 图片地址
     */
    @Column(name = "img_url")
    private String imgUrl;
    /**
     * 标题
     */
    @Column(name = "title")
    private String title;
    /**
     * 链接
     */
    @Column(name = "url")
    private String url;
    /**
     * 焦点图顺序
     */
    @Column(name = "seq")
    private int seq;
    /**
     * 更新者Id
     */
    @Column(name = "update_by")
    private long updateBy;
    /**
     * 更新时间
     */
    @Column(name = "update_at")
    private Date updateAt;
    /**
     * 焦点图是否为空
     */
    @Transient(cache = false)
    private boolean blank;

    public long getFocusImgId() {
        return focusImgId;
    }

    public void setFocusImgId(long focusImgId) {
        this.focusImgId = focusImgId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    public long getOClubId() {
        return oClubId;
    }

    /**
     * 兼容geli
     *
     * @return
     */
    public void setOClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    public long getoClubId() {
        return oClubId;
    }

    public void setoClubId(long oClubId) {
        this.oClubId = oClubId;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    public long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(long updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public boolean isBlank() {
        return blank;
    }

    public void setBlank(boolean blank) {
        this.blank = blank;
    }

    public String converImg(String size) {
        if (StringUtils.isBlank(imgUrl)) {
            return imgUrl;
        }
        if (imgUrl.indexOf("_700x350") != -1) {
            return imgUrl.replace("_700x350", "_" + size);
        }
        if (imgUrl.indexOf("_750x375") != -1) {
            return imgUrl.replace("_750x375", "_" + size);
        }
        return imgUrl.replace(".jpg", "_" + size + ".jpg");
    }

    public String getImgUrl280x140() {
        return converImg("280x140");
    }

    public String getImgUrl520x260() {
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_ws.jpg") != -1) {//默认图片
            return imgUrl;
        }
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_sx.jpg") != -1) {
            return imgUrl;
        }
        return converImg("520x260");
    }

    public String getImgUrl170x85() {
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_sx.jpg") != -1) {//默认图片
            return imgUrl.replace("_sx.jpg", "_sxs.jpg");
        }
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_ws.jpg") != -1) {
            return imgUrl.replace("_ws.jpg", "_wss.jpg");
        }
        return converImg("170x85");
    }
}
